package com.nike.amoeba.adapter

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.nike.amoeba.R
import com.nike.amoeba.bean.DataBean

/**
 * User: Nike
 *  2024/4/23 17:14
 */
class CustomSpinnerAdapter(context: Context, data: ArrayList<DataBean>) :
    ArrayAdapter<DataBean>(context, R.layout.i_spinner_text, data) {

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = super.getView(position, convertView, parent)
        val tv = view.findViewById<TextView>(R.id.tv_text)
        tv.text = getItem(position)?.text
        if (tv.text.equals(context.getString(R.string.found))){
            tv.setTextColor(ContextCompat.getColor(context, R.color.colorAccent))
        }else if (tv.text.equals(context.getString(R.string.missing))){
            tv.setTextColor(ContextCompat.getColor(context, R.color.red_ff0000))
        }else{
            tv.setTextColor(ContextCompat.getColor(context, R.color.black))
        }
        return view
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = super.getDropDownView(position, convertView, parent)
        val tv = view.findViewById<TextView>(R.id.tv_text)
        tv.text = getItem(position)?.text
        if (tv.text.equals(context.getString(R.string.found))){
            tv.setTextColor(ContextCompat.getColor(context, R.color.colorAccent))
        }else if (tv.text.equals(context.getString(R.string.missing))){
            tv.setTextColor(ContextCompat.getColor(context, R.color.red_ff0000))
        }else{
            tv.setTextColor(ContextCompat.getColor(context, R.color.black))
        }
        return view
    }
}